<?
/**
 * dbdSmarty.php :: DBD MVC Smarty Sub Class
 *
 * @package dbdMVC
 * @version 1.1
 * @author Don't Blink Design <info@dontblinkdesign.com>
 * @copyright Copyright (c) 2006-2007 by Don't Blink Design
 */
dbdLoader::load("Smarty.class.php");

/**
 * This classes purpose is to create an implimentation specific
 * version of the Smarty class.
 * @package dbdMVC
 */
class dbdSmarty extends Smarty
{
	/**
	 * Full path to the directory where the 4 smarty directories will live.
	 */
	const VIEW_DIR = "views";
	/**
	 * Flag to designate if the template has been rendered.
	 * @var boolean
	 */
	private $rendered = false;

	private $app_dir = null;
	/**
	 * Smarty contructor that sets implimentation specific variables
	 */
	public function __construct($app_dir)
	{
		parent::Smarty();
		$this->app_dir = $app_dir;
		$this->setOptions();
	}

	private function setOptions()
	{
		$this->template_dir = $this->app_dir.DBD_DS.self::VIEW_DIR.DBD_DS."templates".DBD_DS;
		$this->compile_dir  = $this->app_dir.DBD_DS.self::VIEW_DIR.DBD_DS."templates_c".DBD_DS;
		$this->config_dir   = $this->app_dir.DBD_DS.self::VIEW_DIR.DBD_DS."configs".DBD_DS;
		$this->cache_dir    = $this->app_dir.DBD_DS.self::VIEW_DIR.DBD_DS."cache".DBD_DS;

		$this->caching = false;
		$this->config_overwrite = false;

		$this->register_outputfilter(array($this, "dbdTag"));
	}

	/**
	* executes & displays the template results
	*
	* @param string $resource_name
	* @param string $cache_id
	* @param string $compile_id
	*/
	public function display($resource_name, $cache_id = null, $compile_id = null)
	{
		$this->rendered = true;
		$this->fetch($resource_name, $cache_id, $compile_id, true);
	}

	public function wasRendered()
	{
		return $this->rendered;
	}

	public function dbdTag($tpl, $smarty)
	{
		$tag = "<!--".dbdMVC::getAppName()."-->\n";
		return $tag.$tpl;
	}
}
?>